﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LSQL;

namespace Shopfloormanagement.Rootcause_v02
{
    public partial class Form1: Form
    {
        public static Form1 instance = new Form1();
        public Form1()
        {
            instance = this;
            InitializeComponent();
        }

        private void Init_combobox(ComboBox comboBox)
        {
            DataTable dt = SQL.ReturnDataTableAsc(SystemInfo.SQL, "Departments", $"ParentDepartmentID = 0 and Del_tag = 0");
            comboBox.ValueMember = "ID";
            comboBox.DisplayMember = "DepartmentName";
            comboBox.DataSource = dt;

        }

        private void Add_control()
        {
            int i = panel1.Controls.Count;
            int idx = i + 1;

            Panel panel = new Panel
            {
                Size = new Size(561, 50),
                Location = new Point(3, (i * 56) + 3),
                Name = "pl_" + idx.ToString(),
                BackColor = Color.Red
            };

            Label label = new Label
            {
                Font = new Font("Tahoma", 5),
                Location = new Point(18, 20),
                Name = "lb_" + idx.ToString(),
                Parent = panel
            };

            ComboBox cb = new ComboBox
            {
                Size = new Size(121, 21),
                Location = new Point(81, 16),
                Name = "cb_" + idx.ToString(),
                Parent = panel
            };

            Init_combobox(cb);

            panel1.Controls.Add(panel);
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Add_control();
        }
    }
}
